#coding:utf-8
from __future__ import unicode_literals

from django.db import models
from DjangoUeditor.models import UEditorField
from django.core.urlresolvers import reverse
# Create your models here.
class Tag(models.Model):
    tag_name = models.CharField(max_length=20)
    create_time = models.DateTimeField(auto_now_add=True)
    
    slug = models.CharField('标签网址', max_length=256, db_index=True)

    def get_absolute_url(self):
        return reverse('tag', args=(self.slug,))


    def __unicode__(self):
        return self.tag_name

class Classification(models.Model):
    name = models.CharField(max_length=20)

    slug = models.CharField('分类网址', max_length=256, db_index=True)
    def get_absolute_url(self):
        return reverse('classification', args=(self.slug,))

    def __unicode__(self):
        return self.name

class Author(models.Model):
    name = models.CharField(max_length=30)
    email = models.EmailField(blank=True)
    website = models.URLField(blank=True)

    def __unicode__(self):
        return u'%s' %(self.name)

class Article(models.Model):
    caption = models.CharField(max_length=30)
    intro = models.CharField('内容简介', max_length=256, blank=True)
    #content = models.TextField()
    content = UEditorField('内容', height=300, width=1000,
        default=u'', blank=True, imagePath="uploads/images/",
        toolbars='besttome', filePath='uploads/files/')

    author = models.ForeignKey(Author)
    classification = models.ForeignKey(Classification)
    tags = models.ManyToManyField(Tag, blank=True)

    publish_time = models.DateTimeField(u'发表时间', auto_now_add=True, editable = True)
    update_time = models.DateTimeField(u'更新时间',auto_now=True, null=True)

    slug = models.CharField('文章网址', max_length=256, db_index=True)

    def get_absolute_url(self):
        return reverse('article', args=(self.slug,))
